<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
   <meta name="description"content="{{site.description}}">
    <meta name="keywords" content="{{site.keywords}}"/>
    <meta property="og:title" content="{{site.title}}" />
    <meta property="og:description" content="{{site.description}}" />
     <title>{{site.title}}-{{site.name}}</title>
    {{include './common/meta.html'}}
</head>

<body>
   
    <!-- 头部 -->
    {{include './common/header.html'}}

    <!-- 轮播图 -->
    <section class="row justify-center gap-10  mb-20">
        <div >
            {{@ frag['jsfw-banner']}}
        </div>
    </section>

    <!-- 内容 -->
    {{if article?.content}}
    <section class="pb-20 justify-center row">
        <div class="w-1200 pd-20 article-cont c-3d3d3d f-14">
            {{@ article.content}}
        </div>
    </section>
    {{/if}}


    <!-- 内容 -->
    <section class="pb-20 justify-center row">
        <div class="w-1200 row justify-center pb-20">
            <form id="messageForm" class="row message pd-17">
                <div class="row w-p100">
                    <div class="message-item row col-12">
                        <label class="pl-12" for="name">* 联系人：</label>
                        <input type="text" id="name" name="name" required placeholder="请输入联系人">
                    </div>
                    <div class="message-item row col-12">
                        <label class="pl-12" for="">* 联系电话：</label>
                        <input type="tel" id="tel" name="tel" required placeholder="请输入电话">
                    </div>
                </div>
                <div class="row w-p100">
                    <div class="message-item row col-24">
                        <label class="pl-12" for="company">* 单位名称：</label>
                        <input type="text" id="company" name="company" required placeholder="请输入单位名称">
                    </div>
                </div>

                <div class="row w-p100">
                    <div class="message-item row col-24">
                        <label class="pl-12" for="content">* 留言内容：</label>
                        <textarea class="textarea pd-20 lh-22 flex-1" id="content" name="content" required
                            placeholder="请填写你的需求，我们会尽快与你联系，请留言300字以内："></textarea>
                    </div>
                </div>
                <div class="row w-p100">
                    <div class="col-9" style="margin-left: 120px;">
                        <div id="captcha" style="height:202px;margin:0!important"></div>
                    </div>

                </div>
                <div class="col-9 row w-p100 mt-10" style="margin-left: 120px;">
                    <span class="btn-ok" id="submitBtn">提交</span>
                </div>
            </form>
        </div>
    </section>

    <!-- footer -->
    {{include './common/footer.html'}}

    <!-- 返回顶部 -->
    {{include './common/backtop.html'}}

    {{include './common/js.html'}}


    <script>
        // 显示 toast 提示
        function showToast(msg) {
            // 动态添加 toast 元素
            var toast = $('<div class="toast"><span class="toast-txt"></span></div>');
            toast.find('.toast-txt').text(msg);
            $('body').append(toast);

            // 显示 toast 元素并设置自动消失
            toast.fadeIn('fast', function () {
                setTimeout(function () {
                    toast.fadeOut('fast', function () {
                        toast.remove();
                    });
                }, 1000);
            });
        }

        var filter = false;
        var captcha = sliderCaptcha({
            id: 'captcha',
            width: 200,
            height: 140,
            // sliderL: 42,
            // sliderR: 9,
            offset: 5,//5像素偏差
            loadingText: '正在加载中...',
            failedText: '再试一次',
            barText: '向右滑动填充拼图',
            setSrc: function () {
                return '/public/template/default/img/01.jpg';
            },
            onSuccess: function () {  //成功事件
                filter = true;
                showToast('校验成功，点击提交');
            },
            onFail: function () {
            },
            onRefresh: function () {
            }
        });

        $(document).ready(function () {
            $('#submitBtn').click(function () {
                var name = $('#name').val();
                var tel = $('#tel').val();
                var company = $('#company').val();
                var content = $('#content').val();

                if (name == '' || name.length < 2) {
                    showToast('请正确填写姓名');
                    captcha.reset();
                    return
                }

                if (tel.length != 11) {
                    showToast('请正确填写手机号');
                    return
                }

                if (company.length <= 3) {
                    showToast('请正确填写单位名称全称');
                    captcha.reset();
                    return
                }

                if (content.length < 5) {
                    showToast('请正确填写留言内容');
                    captcha.reset();
                    return
                }

                if (!filter) {
                    showToast('非法提交，校验不通过！');
                    captcha.reset();
                    return
                }

                // 简单的非空校验
                var message = {
                    name: name,
                    tel: tel,
                    company: company,
                    content: content
                };

                $.ajax({
                    url: '/cms/message/create',
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify(message),
                    contentType: 'application/json',
                    success: function (response) {
                        // 处理成功响应
                        showToast('留言提交成功');
                        captcha.reset();
                        $('#name').val('');
                        $('#tel').val('');
                        $('#company').val('');
                        $('#content').val('');
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        showToast('留言提交失败');
                        captcha.reset();
                    }
                });

            });
        });
    </script>

</body>

</html>